      * cobc -x procesar.cbl clientes.cbl -o procesar.exe
      ******************************************************************
       IDENTIFICATION DIVISION.
      ******************************************************************
       PROGRAM-ID. clientes.

      ******************************************************************
       ENVIRONMENT DIVISION.
      ******************************************************************
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
        SELECT ArchivoClientes ASSIGN TO "CLIENTES.BIN"
        ORGANIZATION IS INDEXED
        ACCESS IS DYNAMIC
        RECORD KEY IS K-COD-CLI
        FILE STATUS IS FS-CLI.
      ******************************************************************
       DATA DIVISION.
      ******************************************************************
      *****************************************************
       FILE SECTION.
      *****************************************************
        FD ArchivoClientes LABEL RECORD STANDARD.
        01 RegistroCliente.
         03 K-COD-CLI.
            05 COD-CLI      PIC 9(08).
         03 NOMBRE-CLI      PIC X(30).
         03 DIRECCION-CLI   PIC X(30).
         03 TEL-CLI         PIC X(15).
         03 FEC-NAC         PIC X(10).
         03 OCUPACION       PIC X(20).
      *****************************************************
       WORKING-STORAGE SECTION.
      *****************************************************
       01 FS-CLI            PIC 9(2).

      *****************************************************
       LINKAGE SECTION.
      *****************************************************
       01 Operacion         PIC X(01).
       01 RegistroLink.
         03 COD-CLI         PIC 9(08).
         03 NOMBRE-CLI      PIC X(30).
         03 DIRECCION-CLI   PIC X(30).
         03 TEL-CLI         PIC X(15).
         03 FEC-NAC         PIC X(10).
         03 OCUPACION       PIC X(20).
         
      01 Retorno         PIC X(02).
      ******************************************************************
       PROCEDURE DIVISION USING Operacion, RegistroLink, Retorno.
      ******************************************************************
         Inicio.
            EVALUATE Operacion
              WHEN 'O' PERFORM open-clientes
              WHEN 'A' PERFORM open-io-clientes
              WHEN 'C' PERFORM close-clientes
              WHEN 'R' PERFORM read-clientes
              WHEN 'W' PERFORM write-clientes
              WHEN 'U' PERFORM rewrite-clientes
              WHEN 'D' PERFORM delete-clientes
              WHEN other PERFORM oper-error
            END-EVALUATE.
      ******************************************************************
         open-clientes.
            OPEN INPUT ArchivoClientes
            MOVE FS-CLI TO Retorno
            GOBACK.
      ******************************************************************
         open-io-clientes.
            OPEN I-O ArchivoClientes
            MOVE FS-CLI TO Retorno
            GOBACK.
      ******************************************************************
         close-clientes.
            CLOSE ArchivoClientes
            MOVE FS-CLI TO Retorno
            GOBACK.
      ******************************************************************
         read-clientes.
            MOVE COD-CLI OF RegistroLink
              TO COD-CLI OF RegistroCliente
            READ ArchivoClientes END-READ
            MOVE FS-CLI TO Retorno
            IF FS-CLI = "00"
               PERFORM completar-registro
            END-IF
            GOBACK.
      ******************************************************************
         write-clientes.
           MOVE COD-CLI OF RegistroLink TO COD-CLI OF RegistroCliente
           READ ArchivoClientes END-READ
           IF FS-CLI = "23"
              PERFORM completar-reg-Entrada
              WRITE RegistroCliente END-WRITE
              MOVE FS-CLI TO Retorno
           END-IF
           GOBACK.
      ******************************************************************
         rewrite-clientes.
           MOVE COD-CLI OF RegistroLink TO COD-CLI OF RegistroCliente
           READ ArchivoClientes INTO RegistroCliente END-READ
           IF FS-CLI = "00"
              PERFORM completar-reg-Entrada
              REWRITE RegistroCliente END-REWRITE
              MOVE FS-CLI TO Retorno
           END-IF
           GOBACK.
      ******************************************************************
         delete-clientes.
           MOVE COD-CLI OF RegistroLink TO COD-CLI OF RegistroCliente
           READ ArchivoClientes INTO RegistroCliente END-READ
           IF FS-CLI = "00"
              DELETE ArchivoClientes END-DELETE
              MOVE FS-CLI TO Retorno
           END-IF
           GOBACK.
      ******************************************************************
         oper-error.
           DISPLAY "Operacion desconocida".
           DISPLAY Operacion.
           GOBACK.
      ******************************************************************
          completar-registro.
            MOVE COD-CLI       OF RegistroCliente
              TO COD-CLI       OF RegistroLink
            MOVE NOMBRE-CLI    OF RegistroCliente
              TO NOMBRE-CLI    OF RegistroLink
            MOVE DIRECCION-CLI OF RegistroCliente
              TO DIRECCION-CLI OF RegistroLink
            MOVE TEL-CLI       OF RegistroCliente
              TO TEL-CLI       OF RegistroLink
            MOVE FEC-NAC       OF RegistroCliente
              TO FEC-NAC       OF RegistroLink
            MOVE OCUPACION     OF RegistroCliente
              TO OCUPACION     OF RegistroLink.
      ******************************************************************
          completar-reg-Entrada.
            MOVE COD-CLI       OF RegistroLink
              TO COD-CLI       OF RegistroCliente
            MOVE NOMBRE-CLI    OF RegistroLink
              TO NOMBRE-CLI    OF RegistroCliente
            MOVE DIRECCION-CLI OF RegistroLink
              TO DIRECCION-CLI OF RegistroCliente
            MOVE TEL-CLI       OF RegistroLink
              TO TEL-CLI       OF RegistroCliente
            MOVE FEC-NAC       OF RegistroLink
              TO FEC-NAC       OF RegistroCliente
            MOVE OCUPACION     OF RegistroLink
              TO OCUPACION     OF RegistroCliente.
